package org.efficientsoap.test.serializer;

import android.util.Log;
import java.util.ArrayList;
import java.io.IOException;

import org.efficientsoap.client.EfficientSoapParam;
import org.efficientsoap.client.EfficientSoapSerializer;
import org.efficientsoap.client.IBodySerializer;
import org.efficientsoap.test.datatypes.*;

/**
 * a serializing helper class for the input parameter using the
 * EfficientSoap.org SOAP client library project.
 * 
 * @author Christian Rau
 */
public class DoubleInBooleanListOutInputSerializer extends
		EfficientSoapSerializer implements
		IBodySerializer<ArrayList<EfficientSoapParam<?>>> {

	private static final String TAG = DoubleInBooleanListOutInputSerializer.class
			.getSimpleName();
	private static final String NAMESPACE = "http://efficientsoap.org/test/datatypes";

	@Override
	public void serializeBody(ArrayList<EfficientSoapParam<?>> paramList)
			throws IllegalArgumentException, IllegalStateException, IOException {
		serializer.startTag(this.getSoapNamespaceURI(), "Body");
		serializeMethod(paramList);
		serializer.endTag(this.getSoapNamespaceURI(), "Body");
	}

	private void serializeMethod(ArrayList<EfficientSoapParam<?>> paramList)
			throws IllegalArgumentException, IllegalStateException, IOException {
		serializer.startTag(NAMESPACE, "doubleInBooleanListOut");
		// serialize parameter list
		if (paramList != null) {
			for (EfficientSoapParam<?> param : paramList) {
				if (param.getTag().contentEquals("doubleParam"))
					serializeDoubleParam(this, (Double) param.getParam(),
   							param.getTag());
			}
		}
		serializer.endTag(NAMESPACE, "doubleInBooleanListOut");
	}

	public static void serializeDoubleParam(
			EfficientSoapSerializer<?> eSoapSerializer, Double input, String tag)
			throws IllegalArgumentException, IllegalStateException, IOException {
		eSoapSerializer.getSerializer().startTag(NAMESPACE, tag);
		eSoapSerializer.serializeDoubleElem(input, "doubleParam");
		eSoapSerializer.getSerializer().endTag(NAMESPACE, tag);
	}
}
